<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book Python数据分析课程讲义 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>ndarray的元素处理 | Python数据分析课程讲义</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        <meta name="author" content="BigCat">
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-tbfed-pagefooter/footer.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../file/part02/2.4.html" />
    
    
    <link rel="prev" href="../../file/part02/2.2.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="2.3"
        data-chapter-title="ndarray的元素处理"
        data-filepath="file/part02/2.3.md"
        data-basepath="../.."
        data-revision="Thu Apr 27 2017 00:50:19 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        传智播客Python学院数据分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="file/part01/1.html">
            
                
                    <a href="../../file/part01/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        一、工作环境准备及数据分析建模理论基础
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="file/part01/1.1.html">
            
                
                    <a href="../../file/part01/1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Python 3.x新特性和编码回顾
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="file/part01/1.2.html">
            
                
                    <a href="../../file/part01/1.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        DIKW模型与数据工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="file/part01/1.3.html">
            
                
                    <a href="../../file/part01/1.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        数据分析建模理论基础
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="file/part02/2.html">
            
                
                    <a href="../../file/part02/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        二、科学计算工具NumPy
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="file/part02/2.1.html">
            
                
                    <a href="../../file/part02/2.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        ndarray的创建与数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="file/part02/2.2.html">
            
                
                    <a href="../../file/part02/2.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        ndarray的矩阵处理
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.3" data-path="file/part02/2.3.html">
            
                
                    <a href="../../file/part02/2.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        ndarray的元素处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="file/part02/2.4.html">
            
                
                    <a href="../../file/part02/2.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        实战案例：2016美国总统大选民意调查统计
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="file/part03/3.html">
            
                
                    <a href="../../file/part03/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        三、数据分析工具Pandas
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="file/part03/3.1.html">
            
                
                    <a href="../../file/part03/3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        Pandas的数据结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="file/part03/3.2.html">
            
                
                    <a href="../../file/part03/3.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        Pandas的索引操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="file/part03/3.3.html">
            
                
                    <a href="../../file/part03/3.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Pandas的对齐运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="file/part03/3.4.html">
            
                
                    <a href="../../file/part03/3.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        Pandas的函数应用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="file/part03/3.5.html">
            
                
                    <a href="../../file/part03/3.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        Pandas的层级索引
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="file/part03/3.6.html">
            
                
                    <a href="../../file/part03/3.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        Pandas统计计算和描述
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="file/part03/3.7.html">
            
                
                    <a href="../../file/part03/3.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        Pandas分组与聚合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="file/part03/3.8.html">
            
                
                    <a href="../../file/part03/3.8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        数据清洗、合并、转化和重构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="file/part03/3.9.html">
            
                
                    <a href="../../file/part03/3.9.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        聚类模型 -- K-Means介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="file/part03/3.10.html">
            
                
                    <a href="../../file/part03/3.10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        实战案例：全球食品数据分析
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="file/part04/4.html">
            
                
                    <a href="../../file/part04/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        四、数据可视化工具
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="file/part04/4.1.html">
            
                
                    <a href="../../file/part04/4.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        Matplotlib绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="file/part04/4.2.html">
            
                
                    <a href="../../file/part04/4.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        Seaborn绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="file/part04/4.3.html">
            
                
                    <a href="../../file/part04/4.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        Bokeh绘图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="file/part04/4.4.html">
            
                
                    <a href="../../file/part04/4.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        实战案例：世界高峰数据可视化
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="file/part06/6.html">
            
                
                    <a href="../../file/part06/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        五、自然语言处理NLTK
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="file/part06/6.1.html">
            
                
                    <a href="../../file/part06/6.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        NLTK与自然语言处理基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="file/part06/6.2.html">
            
                
                    <a href="../../file/part06/6.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        jieba分词
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="file/part06/6.3.html">
            
                
                    <a href="../../file/part06/6.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        情感分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="file/part06/6.4.html">
            
                
                    <a href="../../file/part06/6.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        文本相似度和分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="file/part06/6.6.html">
            
                
                    <a href="../../file/part06/6.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        实战案例：微博情感分析
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >Python数据分析课程讲义</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <blockquote>
<h2 id="&#x5143;&#x7D20;&#x8BA1;&#x7B97;&#x51FD;&#x6570;">&#x5143;&#x7D20;&#x8BA1;&#x7B97;&#x51FD;&#x6570;</h2>
</blockquote>
<ol>
<li><p><code>ceil()</code>: &#x5411;&#x4E0A;&#x6700;&#x63A5;&#x8FD1;&#x7684;&#x6574;&#x6570;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</p>
</li>
<li><p><code>floor()</code>: &#x5411;&#x4E0B;&#x6700;&#x63A5;&#x8FD1;&#x7684;&#x6574;&#x6570;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</p>
</li>
<li><code>rint()</code>: &#x56DB;&#x820D;&#x4E94;&#x5165;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li><code>isnan()</code>: &#x5224;&#x65AD;&#x5143;&#x7D20;&#x662F;&#x5426;&#x4E3A; NaN(Not a Number)&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li><code>multiply()</code>: &#x5143;&#x7D20;&#x76F8;&#x4E58;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li><code>divide()</code>: &#x5143;&#x7D20;&#x76F8;&#x9664;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li><code>abs()</code>&#xFF1A;&#x5143;&#x7D20;&#x7684;&#x7EDD;&#x5BF9;&#x503C;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li><code>where(condition, x, y)</code>: &#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;x if condition else y</li>
</ol>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF08;1&#x3001;2&#x3001;3&#x3001;4&#x3001;5&#x3001;6&#x3001;7&#xFF09;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># randn() &#x8FD4;&#x56DE;&#x5177;&#x6709;&#x6807;&#x51C6;&#x6B63;&#x6001;&#x5206;&#x5E03;&#x7684;&#x5E8F;&#x5217;&#x3002;</span>
arr = np.random.randn(<span class="hljs-number">2</span>,<span class="hljs-number">3</span>)

print(arr)

print(np.ceil(arr))

print(np.floor(arr))

print(np.rint(arr))

print(np.isnan(arr))

print(np.multiply(arr, arr))

print(np.divide(arr, arr))

print(np.where(arr &gt; <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, -<span class="hljs-number">1</span>))
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># print(arr)</span>
[[-<span class="hljs-number">0.75803752</span>  <span class="hljs-number">0.0314314</span>   <span class="hljs-number">1.15323032</span>]
 [ <span class="hljs-number">1.17567832</span>  <span class="hljs-number">0.43641395</span>  <span class="hljs-number">0.26288021</span>]]

<span class="hljs-comment"># print(np.ceil(arr))</span>
[[-<span class="hljs-number">0.</span>  <span class="hljs-number">1.</span>  <span class="hljs-number">2.</span>]
 [ <span class="hljs-number">2.</span>  <span class="hljs-number">1.</span>  <span class="hljs-number">1.</span>]]

<span class="hljs-comment"># print(np.floor(arr))</span>
[[-<span class="hljs-number">1.</span>  <span class="hljs-number">0.</span>  <span class="hljs-number">1.</span>]
 [ <span class="hljs-number">1.</span>  <span class="hljs-number">0.</span>  <span class="hljs-number">0.</span>]]

<span class="hljs-comment"># print(np.rint(arr))</span>
[[-<span class="hljs-number">1.</span>  <span class="hljs-number">0.</span>  <span class="hljs-number">1.</span>]
 [ <span class="hljs-number">1.</span>  <span class="hljs-number">0.</span>  <span class="hljs-number">0.</span>]]

<span class="hljs-comment"># print(np.isnan(arr))</span>
[[<span class="hljs-keyword">False</span> <span class="hljs-keyword">False</span> <span class="hljs-keyword">False</span>]
 [<span class="hljs-keyword">False</span> <span class="hljs-keyword">False</span> <span class="hljs-keyword">False</span>]]

<span class="hljs-comment"># print(np.multiply(arr, arr))</span>
[[  <span class="hljs-number">5.16284053e+00</span>   <span class="hljs-number">1.77170104e+00</span>   <span class="hljs-number">3.04027254e-02</span>]
 [  <span class="hljs-number">5.11465231e-03</span>   <span class="hljs-number">3.46109263e+00</span>   <span class="hljs-number">1.37512421e-02</span>]]

<span class="hljs-comment"># print(np.divide(arr, arr))</span>
[[ <span class="hljs-number">1.</span>  <span class="hljs-number">1.</span>  <span class="hljs-number">1.</span>]
 [ <span class="hljs-number">1.</span>  <span class="hljs-number">1.</span>  <span class="hljs-number">1.</span>]]

<span class="hljs-comment"># print(np.where(arr &gt; 0, 1, -1))</span>
[[ <span class="hljs-number">1</span>  <span class="hljs-number">1</span> -<span class="hljs-number">1</span>]
 [-<span class="hljs-number">1</span>  <span class="hljs-number">1</span>  <span class="hljs-number">1</span>]]
</code></pre>
<blockquote>
<h2 id="&#x5143;&#x7D20;&#x7EDF;&#x8BA1;&#x51FD;&#x6570;">&#x5143;&#x7D20;&#x7EDF;&#x8BA1;&#x51FD;&#x6570;</h2>
</blockquote>
<ol>
<li><p><code>np.mean()</code>, <code>np.sum()</code>&#xFF1A;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x5E73;&#x5747;&#x503C;&#xFF0C;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x548C;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</p>
</li>
<li><p><code>np.max()</code>, <code>np.min()</code>&#xFF1A;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x6700;&#x5927;&#x503C;&#xFF0C;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x6700;&#x5C0F;&#x503C;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</p>
</li>
<li><code>np.std()</code>, <code>np.var()</code>&#xFF1A;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x6807;&#x51C6;&#x5DEE;&#xFF0C;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x65B9;&#x5DEE;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li><code>np.argmax()</code>, <code>np.argmin()</code>&#xFF1A;&#x6700;&#x5927;&#x503C;&#x7684;&#x4E0B;&#x6807;&#x7D22;&#x5F15;&#x503C;&#xFF0C;&#x6700;&#x5C0F;&#x503C;&#x7684;&#x4E0B;&#x6807;&#x7D22;&#x5F15;&#x503C;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li><code>np.cumsum()</code>, <code>np.cumprod()</code>&#xFF1A;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x90FD;&#x662F;&#x4E4B;&#x524D;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684; &#x7D2F;&#x52A0;&#x548C; &#x548C; &#x7D2F;&#x4E58;&#x79EF;&#xFF0C;&#x53C2;&#x6570;&#x662F; number &#x6216; array</li>
<li>&#x591A;&#x7EF4;&#x6570;&#x7EC4;&#x9ED8;&#x8BA4;&#x7EDF;&#x8BA1;&#x5168;&#x90E8;&#x7EF4;&#x5EA6;&#xFF0C;<code>axis</code>&#x53C2;&#x6570;&#x53EF;&#x4EE5;&#x6309;&#x6307;&#x5B9A;&#x8F74;&#x5FC3;&#x7EDF;&#x8BA1;&#xFF0C;&#x503C;&#x4E3A;<code>0</code>&#x5219;&#x6309;&#x5217;&#x7EDF;&#x8BA1;&#xFF0C;&#x503C;&#x4E3A;<code>1</code>&#x5219;&#x6309;&#x884C;&#x7EDF;&#x8BA1;&#x3002;</li>
</ol>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">arr = np.arange(<span class="hljs-number">12</span>).reshape(<span class="hljs-number">3</span>,<span class="hljs-number">4</span>)
print(arr)

print(np.cumsum(arr)) <span class="hljs-comment"># &#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x4E00;&#x7EF4;&#x6570;&#x7EC4;&#xFF0C;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x90FD;&#x662F;&#x4E4B;&#x524D;&#x6240;&#x6709;&#x5143;&#x7D20;&#x7684; &#x7D2F;&#x52A0;&#x548C;</span>

print(np.sum(arr)) <span class="hljs-comment"># &#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x548C;</span>

print(np.sum(arr, axis=<span class="hljs-number">0</span>)) <span class="hljs-comment"># &#x6570;&#x7EC4;&#x7684;&#x6309;&#x5217;&#x7EDF;&#x8BA1;&#x548C;</span>

print(np.sum(arr, axis=<span class="hljs-number">1</span>)) <span class="hljs-comment"># &#x6570;&#x7EC4;&#x7684;&#x6309;&#x884C;&#x7EDF;&#x8BA1;&#x548C;</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment"># print(arr)</span>
[[ <span class="hljs-number">0</span>  <span class="hljs-number">1</span>  <span class="hljs-number">2</span>  <span class="hljs-number">3</span>]
 [ <span class="hljs-number">4</span>  <span class="hljs-number">5</span>  <span class="hljs-number">6</span>  <span class="hljs-number">7</span>]
 [ <span class="hljs-number">8</span>  <span class="hljs-number">9</span> <span class="hljs-number">10</span> <span class="hljs-number">11</span>]]

<span class="hljs-comment"># print(np.cumsum(arr)) </span>
[ <span class="hljs-number">0</span>  <span class="hljs-number">1</span>  <span class="hljs-number">3</span>  <span class="hljs-number">6</span> <span class="hljs-number">10</span> <span class="hljs-number">15</span> <span class="hljs-number">21</span> <span class="hljs-number">28</span> <span class="hljs-number">36</span> <span class="hljs-number">45</span> <span class="hljs-number">55</span> <span class="hljs-number">66</span>]

<span class="hljs-comment"># print(np.sum(arr)) # &#x6240;&#x6709;&#x5143;&#x7D20;&#x7684;&#x548C;</span>
<span class="hljs-number">66</span>

<span class="hljs-comment"># print(np.sum(arr, axis=0)) # 0&#x8868;&#x793A;&#x5BF9;&#x6570;&#x7EC4;&#x7684;&#x6BCF;&#x4E00;&#x5217;&#x7684;&#x7EDF;&#x8BA1;&#x548C;</span>
[<span class="hljs-number">12</span> <span class="hljs-number">15</span> <span class="hljs-number">18</span> <span class="hljs-number">21</span>]

<span class="hljs-comment"># print(np.sum(arr, axis=1)) # 1&#x8868;&#x793A;&#x6570;&#x7EC4;&#x7684;&#x6BCF;&#x4E00;&#x884C;&#x7684;&#x7EDF;&#x8BA1;&#x548C;</span>
[ <span class="hljs-number">6</span> <span class="hljs-number">22</span> <span class="hljs-number">38</span>]
</code></pre>
<blockquote>
<h2 id="&#x5143;&#x7D20;&#x5224;&#x65AD;&#x51FD;&#x6570;">&#x5143;&#x7D20;&#x5224;&#x65AD;&#x51FD;&#x6570;</h2>
</blockquote>
<ol>
<li><code>np.any()</code>: &#x81F3;&#x5C11;&#x6709;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#x6EE1;&#x8DB3;&#x6307;&#x5B9A;&#x6761;&#x4EF6;&#xFF0C;&#x8FD4;&#x56DE;True</li>
<li><code>np.all()</code>: &#x6240;&#x6709;&#x7684;&#x5143;&#x7D20;&#x6EE1;&#x8DB3;&#x6307;&#x5B9A;&#x6761;&#x4EF6;&#xFF0C;&#x8FD4;&#x56DE;True</li>
</ol>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">arr = np.random.randn(<span class="hljs-number">2</span>,<span class="hljs-number">3</span>)
print(arr)

print(np.any(arr &gt; <span class="hljs-number">0</span>))
print(np.all(arr &gt; <span class="hljs-number">0</span>))
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">[[ <span class="hljs-number">0.05075769</span> -<span class="hljs-number">1.31919688</span> -<span class="hljs-number">1.80636984</span>]
 [-<span class="hljs-number">1.29317016</span> -<span class="hljs-number">1.3336612</span>  -<span class="hljs-number">0.19316432</span>]]

<span class="hljs-keyword">True</span>
<span class="hljs-keyword">False</span>
</code></pre>
<blockquote>
<h2 id="&#x5143;&#x7D20;&#x53BB;&#x91CD;&#x6392;&#x5E8F;&#x51FD;&#x6570;">&#x5143;&#x7D20;&#x53BB;&#x91CD;&#x6392;&#x5E8F;&#x51FD;&#x6570;</h2>
</blockquote>
<p><code>np.unique()</code>:&#x627E;&#x5230;&#x552F;&#x4E00;&#x503C;&#x5E76;&#x8FD4;&#x56DE;&#x6392;&#x5E8F;&#x7ED3;&#x679C;&#xFF0C;&#x7C7B;&#x4F3C;&#x4E8E;Python&#x7684;set&#x96C6;&#x5408;</p>
<p>&#x793A;&#x4F8B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">arr = np.array([[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>], [<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>]])
print(arr)

print(np.unique(arr))
</code></pre>
<p>&#x8FD0;&#x884C;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-python">[[<span class="hljs-number">1</span> <span class="hljs-number">2</span> <span class="hljs-number">1</span>]
 [<span class="hljs-number">2</span> <span class="hljs-number">3</span> <span class="hljs-number">4</span>]]

[<span class="hljs-number">1</span> <span class="hljs-number">2</span> <span class="hljs-number">3</span> <span class="hljs-number">4</span>]
</code></pre>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; BigCat all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x300C;Revision Time:
2017-03-12 23:55:41&#x300D;
</span></footer>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../file/part02/2.2.html" class="navigation navigation-prev " aria-label="Previous page: ndarray的矩阵处理"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../file/part02/2.4.html" class="navigation navigation-next " aria-label="Next page: 实战案例：2016美国总统大选民意调查统计"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"disqus":{"shortName":"gitbookuse"},"github":{"url":"https://github.com/dododream"},"search-pro":{"cutWordLib":"nodejieba","defineWord":["gitbook-use"]},"sharing":{"weibo":true,"facebook":true,"twitter":true,"google":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"tbfed-pagefooter":{"copyright":"Copyright © BigCat","modify_label":"「Revision Time:","modify_format":"YYYY-MM-DD HH:mm:ss」"},"baidu":{"token":"ff100361cdce95dd4c8fb96b4009f7bc"},"sitemap":{"hostname":"http://www.treenewbee.top"},"donate":{"wechat":"http://weixin.png","alipay":"http://alipay.png","title":"","button":"赏","alipayText":"支付宝打赏","wechatText":"微信打赏"},"edit-link":{"base":"https://github.com/dododream/edit","label":"Edit This Page"},"splitter":{},"toggle-chapters":{},"highlight":{},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book Python数据分析课程讲义 -->
</html>
